import flet as ft
from flet import (
	Page,
	colors
)

if __name__ == "__main__":
	def main(page: Page):
		page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
		
		def handle_dismissal(e):
			page.add(ft.Text("Drawer dismissed"))
		
		def handle_change(e):
			page.add(ft.Text(f"Selected Index changed: {e.control.selected_index}"))
		
		# page.close(drawer)
		
		drawer = ft.NavigationDrawer(
			on_dismiss=handle_dismissal,
			on_change=handle_change,
			controls=[
				ft.Container(height=12),
				ft.NavigationDrawerDestination(
					label="1",
					icon=ft.icons.DOOR_BACK_DOOR_OUTLINED,
					selected_icon=ft.Icon(ft.icons.DOOR_BACK_DOOR),
				),
				ft.Divider(thickness=2),
				ft.NavigationDrawerDestination(
					icon=ft.Icon(ft.icons.MAIL_OUTLINED),
					label="Item 2",
					selected_icon=ft.icons.MAIL,
				),
				ft.NavigationDrawerDestination(
					icon=ft.Icon(ft.icons.PHONE_OUTLINED),
					label="Item 3",
					selected_icon=ft.icons.PHONE,
				),
			],
		)
		
		page.add(ft.ElevatedButton("显示侧边栏", on_click=lambda e: page.open(drawer)))
	
	
	ft.app(target=main)